#include "LPC11XX.H"

unsigned int status;
static volatile unsigned int ticks = 0;

void Led_ON(int a)
{
	LPC_GPIO2->DATA &= ~(1<<a);
}

void Led_OFF(int b)
{
	LPC_GPIO2->DATA |= (1<<b);
}

void LedInit(void)
{
	LPC_SYSCON->SYSAHBCLKCTRL |= (1<<16);
	LPC_IOCON->PIO2_0 &= ~0x07;
	LPC_IOCON->PIO2_0 |= 0x00;
	LPC_IOCON->PIO2_1 &= ~0x07;
	LPC_IOCON->PIO2_1 |= 0x00;
	LPC_IOCON->PIO2_2 &= ~0x07;
	LPC_IOCON->PIO2_2 |= 0x00;
	LPC_IOCON->PIO2_3 &= ~0x07;
	LPC_IOCON->PIO2_3 |= 0x00;
	LPC_IOCON->PIO2_4 &= ~0x07;
	LPC_IOCON->PIO2_4 |= 0x00;
	LPC_IOCON->PIO2_5 &= ~0x07;
	LPC_IOCON->PIO2_5 |= 0x00;
	LPC_IOCON->PIO2_6 &= ~0x07;
	LPC_IOCON->PIO2_6 |= 0x00;
	LPC_IOCON->PIO2_7 &= ~0x07;
	LPC_IOCON->PIO2_7 |= 0x00;
	LPC_SYSCON->SYSAHBCLKCTRL &= ~(1<<16);
	LPC_SYSCON->SYSAHBCLKCTRL |= (1<<6);
	LPC_GPIO2->DIR =0xFF;
	LPC_GPIO2->DATA =0xFF;

}

 void T32B1_Init(void)
 {
	 LPC_SYSCON->SYSAHBCLKCTRL|=(1<<10);
	 LPC_TMR32B1->IR = 0X01;
	 LPC_TMR32B1->MCR = 0X04;
 }
 
 void T32B1_DelayMs(uint16_t ms)
 {
	 LPC_TMR32B1->TCR=0X02;
	 LPC_TMR32B1->PR=0;
	 LPC_TMR32B1->MR0 = ms * (SystemCoreClock/1000);
	 LPC_TMR32B1->TCR = 0X01;
	 while(LPC_TMR32B1->TCR&0X01);
 }
 
 int main()
 {
	 int i;
	 LedInit();
	 T32B1_Init();
	 while(1)
	 { 
		 for(i=0;i<=7;i++)
		 {
		 T32B1_DelayMs(100);
		 Led_ON(i);
		 T32B1_DelayMs(100);
		 Led_OFF(i);
		 }
		 
		 for(i=6;i>0;i--)
		 {
		 T32B1_DelayMs(100);
		 Led_ON(i);
		 T32B1_DelayMs(100);
		 Led_OFF(i);
		 }
	 }
}


